﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TPL.Xna.Common
{
    public abstract class SpriteArea
    {
        private readonly GraphicsDevice _graphicsDevice;

        protected SpriteArea(GraphicsDevice graphicsDevice)
        {
            _graphicsDevice = graphicsDevice;
        }

        private ShapeSprite _shape;
        /// <summary>
        /// Shape of the collision area.
        /// </summary>
        public ShapeSprite Shape { get { return (_shape ?? (_shape = CreateShape(_graphicsDevice))); } }

        /// <summary>
        /// Create the shape that is used as sprite area.
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <returns></returns>
        protected abstract ShapeSprite CreateShape(GraphicsDevice graphicsDevice);

        /// <summary>
        /// Whether some collisions have ever happened.
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public abstract bool CollideWith(SpriteArea area);

        /// <summary>
        /// Whether this area is out of the given bound.
        /// </summary>
        /// <param name="bound"></param>
        /// <returns></returns>
        public abstract bool IsOutOfBound(Rectangle bound);
    }
}